#!/usr/bin/env python
# coding: utf-8

class Item:
    """
        Purpose: This class represents the item in a store.
        name: The name of a item in a store.
        price: The price of the item.
        category: Which category the item belongs to.
        store: where the item lay in.
        __str__():string format.
        __lt__():compare with each othre via price.
        getters():get name of a item.
        setters():set name of a item.
    """
    def __init__(self, name, price, category, store):
        self.name = name
        self.price = price
        self.category = category
        self.store = store
        
    def __str__(self):
        return self.name + ", " + self.category + ", " + self.store + ": " + "$" + str(self.price) 
    
    def __lt__(self, item):
        if self.price < item.price:
            return True
        else:
            return False
        
    def getters(self):
        return self.name
    
    def setters(self,new_name):
        self.name = new_name

class Store:
    """
    Purpose: This class represents store, that contains many items.
    name: The name of a store.
    filename: The imformation file of a store.
    __str__(): String format.
    __setters__(): Set the name of a store.
    __getters__(): Get the name of a store.
    """
    def __init__(self, name, filename):
        self.name = name
        self.filename = filename
        self.items = []
        with open(self.filename,'r') as f:
            content = f.readlines()[1:]
        for item in content:
            name = item.strip().split(",")[0]
            price = float(item.strip().split(",")[1])
            category = item.strip().split(",")[2]
            self.items.append(Item(name, price, category, self.name))
    def __str__(self):
        temp_items = [str(i) for i in self.items]
        return  self.name + '\n' + '\n'.join(temp_items)
    def __setters__(self, new_name):
        self.name = new_name
    def __getters__(self):
        return self.name
    
def cheap_outfit(store_list):
    """
    Purpose: A function to get the cheapest outfit from store_list.
    store_list: A list to contain Store class.
    return: A dictionary that has key of category and value of item that is cheapest in stores.
    """
    categories = ['Head', 'Torso', 'Legs', 'Feet']
    dictionary = {}
    for i in range(len(categories)):
        store_items = []
        for store in store_list:
            for item in store.items:
                if item.category == categories[i]:
                    store_items.append(item)
        dictionary[categories[i]] = min(store_items)
    return dictionary

